#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#define int __int128
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define pii pair<int,int>
#define fi first
#define se second
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=5e6+5,base=999983,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
int _base=1;
inline int mol(const int x){return x-Mod*((__int128)_base*x>>64);}
inline void Add(int &x,const int y){x=mol(x+y);}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}int n,v[N],c[N],x[N];
int dp[2][N];
int qzh[N];
signed main(){
	_base=((__int128)_base<<64)/Mod;
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read();
	For(i,1,n) v[i]=read();
	For(i,1,n) c[i]=read();
	bool flag=0;
	For(i,1,n-1) x[i]=read();
	For(i,1,n-1) if(x[i]!=1) flag=1;
	if(!flag){
		Rof(i,n,1) v[i]=max(v[i+1],v[i]);
		int ans=0;
		For(i,1,n) ans+=v[i]*c[i],ans%=Mod;
		print(ans);
		return 0;
	}
	memset(dp[1],-0x3f,sizeof(dp[1]));
	dp[1][0]=0; 
	int lst=0;
	For(i,1,n-1){
		int llst=lst;
		qzh[lst+1]=-1e16; 
		Rof(j,lst,0)qzh[j]=max(v[i]*j+dp[i&1][j],qzh[j+1]);
		For(t,0,c[i]+llst){
			if(t*x[i]-c[i]>llst) break; 
			dp[(i+1)&1][t]=(c[i]-t*x[i])*v[i]+qzh[max((int)0,t*x[i]-c[i])];
			lst=t;
		}
	}
	int ans=0;
	Rof(j,lst,0){
		ans=max(ans,dp[n&1][j]+(c[n]+j)*v[n]);
	}print(ans%Mod);
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}



